﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TrackSystem.Entities.Models;

namespace TrackSystem.EntityFramework.Mapping
{
    public class LogicMap : IEntityTypeConfiguration<LogicTable>
    {
        public void Configure(EntityTypeBuilder<LogicTable> builder)
        {
            builder.ToTable("Logic");

            builder.HasKey(s => s.Id);
            builder.HasIndex(s => s.Id).IsUnique();

            builder.Property(s => s.Name).HasMaxLength(50).IsRequired();
            builder.HasIndex(s => s.Name).IsUnique();

            builder.Property(s => s.Description).HasMaxLength(200);

            builder.HasOne(s => s.Equip)
                .WithMany(e => e.Logics)
                .HasForeignKey(s => s.equipId)
                .OnDelete(DeleteBehavior.NoAction);
        }
    }
}
